#pragma once

#include "mysql/mysql.h"
#include <string>

//mysql操作
class CMySQLOper
{
private:
    MYSQL *pMysqlOp;      //操作句柄

private://数据库参数
    std::string dbHost;         
    unsigned int dbPort;
    std::string dbUser;
    std::string dbPwd;
    std::string dbSchema;

    std::string errMsg;     //错误信息
public:
    CMySQLOper();
    ~CMySQLOper();

    //测试数据库连接
    static bool TestMysql(std::string &db_host, unsigned int db_port, std::string &db_user,
        std::string &db_pwd, std::string db_schema,std::string &err);

    //连接数据库
    bool Connect(std::string &db_host, unsigned int db_port, std::string &db_user,
        std::string &db_pwd, std::string db_schema);

    //增
    int Add();

    //删
    bool Delete();

    //改
    bool Alter();

    //查数据，成功返回true，失败返回false，调用后必须清空集合
    MYSQL_RES* select(std::string query);

    //关闭连接
    void CloseConnect(void);

    //错误信息
    std::string GetLastErrMsg(void){ return errMsg;}

};